function showview() {
  switch(view) {
    case 1:
      return showprop();
    case 2:
      return showevnt();
    case 3:
      return showtree();
    case 4:
      return showcode();
  }
  return false;
}

function showform() {
  //display form
  document.getElementById('tool').innerHTML = toolbar();
  document.getElementById('form').innerHTML = drawForm(MyForm);
  setpointer();  
  return true;
}

function showprop() {
  //check for form
  if(MyForm==null) {
    alert('You must start a new project first!');
    return false;
  }
  
  //show properties
  switch(MyProp.type) {
    case "act":
      document.getElementById('prop').innerHTML = propActivex(MyProp);
      break;  
    case "but":
      document.getElementById('prop').innerHTML = propButton(MyProp);
      break;      
    case "doc":
      document.getElementById('prop').innerHTML = propDockablePanel(MyProp);
      break;
    case "drp":
      document.getElementById('prop').innerHTML = propDropDown(MyProp);
      break;      
    case "edt":
      document.getElementById('prop').innerHTML = propEdit(MyProp);
      break;              
    case "frm":
      document.getElementById('prop').innerHTML = propForm(MyProp);
      break;
    case "chk":
      document.getElementById('prop').innerHTML = propCheckBox(MyProp);
      break;    
    case "lbl":
      document.getElementById('prop').innerHTML = propLabel(MyProp);
      break;    
    case "pan":
      document.getElementById('prop').innerHTML = propPanel(MyProp);
      break;     
    case "rad":
      document.getElementById('prop').innerHTML = propRadioButton(MyProp);
      break;     
    case "spn":
      document.getElementById('prop').innerHTML = propSpinEdit(MyProp);
      break;     
    case "bar":
      document.getElementById('prop').innerHTML = propTrackBar(MyProp);
      break;       
    case "tra":
      document.getElementById('prop').innerHTML = propTranspPanel(MyProp);
      break;
    case "opt":
      document.getElementById('prop').innerHTML = propOptionSheet(MyProp);
      break;      
    default:
      document.getElementById('prop').innerHTML = "[Properties not available]";
  }
  
  //update tabs
  view = 1;
  document.getElementById('tabs').innerHTML = addtabs();
  return showform();
}

function showevnt() {
  //check for form
  if(MyForm==null) {
    alert('You must start a new project first!');
    return false;
  }
  
  //show events
  switch(MyProp.type) {
    case "act":
      document.getElementById('prop').innerHTML = evntActivex(MyProp);
      break;  
    case "but":
      document.getElementById('prop').innerHTML = evntButton(MyProp);
      break;      
    case "doc":
      document.getElementById('prop').innerHTML = evntDockablePanel(MyProp);
      break;
    case "drp":
      document.getElementById('prop').innerHTML = evntDropDown(MyProp);
      break;      
    case "edt":
      document.getElementById('prop').innerHTML = evntEdit(MyProp);
      break;              
    case "frm":
      document.getElementById('prop').innerHTML = evntForm(MyProp);
      break;
    case "chk":
      document.getElementById('prop').innerHTML = evntCheckBox(MyProp);
      break;    
    case "lbl":
      document.getElementById('prop').innerHTML = evntLabel(MyProp);
      break;    
    case "pan":
      document.getElementById('prop').innerHTML = evntPanel(MyProp);
      break;     
    case "rad":
      document.getElementById('prop').innerHTML = evntRadioButton(MyProp);
      break;     
    case "spn":
      document.getElementById('prop').innerHTML = evntSpinEdit(MyProp);
      break;     
    case "bar":
      document.getElementById('prop').innerHTML = evntTrackBar(MyProp);
      break;       
    case "tra":
      document.getElementById('prop').innerHTML = evntTranspPanel(MyProp);
      break;      
    default:
      document.getElementById('prop').innerHTML = "[Events not available]";
  }
  
  //update tabs
  view = 2;
  document.getElementById('tabs').innerHTML = addtabs();
  return showform();
}

function showcode() {
  //check for form
  if(MyForm==null) {
    alert('You must start a new project first!');
    return false;
  }
  
  //create form
  subs = new Array();
  var vbs = "<p align='center'><textarea id='code' cols=68 rows=20 wrap=off>";
  vbs += "'*******************************************************************'\n";
  vbs += "'* Form produced by MMVBS Form Creator (http://trixmoto.net/mmvbs) *'\n";
  vbs += "'*******************************************************************'\n";
  vbs += "\n";
  switch(MyForm.type) {
    case "frm":
      vbs += "Dim "+MyForm.onam+" : Set "+MyForm.onam+" = SDB.UI.NewForm\n";
      vbs += MyForm.onam+".BorderStyle = "+MyForm.bord+"\n";
      if(MyForm.capt!="") {
        vbs += MyForm.onam+".Caption = \""+MyForm.capt+"\"\n";
      }
      if(MyForm.posi>0) {
        vbs += MyForm.onam+".FormPosition = "+MyForm.posi+"\n";
      }
      if(MyForm.save!="") {
        vbs += MyForm.onam+".SavePositionName = \""+MyForm.save+"\"\n";
      }
      if(MyForm.stay) {
        vbs += MyForm.onam+".StayOnTop = True\n";
      }
      if(MyForm.oclo!="") {
        vbs += "Script.RegisterEvent "+MyForm.onam+", \"OnClose\", \""+MyForm.oclo+"\"\n";
        addtosubs(MyForm.oclo);
      }
      break;
    case "doc":
      if(MyForm.pers) {
        var name = MyForm.name;
        if(name=="") {
          name = MyForm.onam;
        }
        vbs += "Dim "+MyForm.onam+" : Set "+MyForm.onam+" = SDB.UI.NewDockablePersistentPanel(\""+name+"\")\n";
      }
      else {
        vbs += "Dim "+MyForm.onam+" : Set "+MyForm.onam+" = SDB.UI.NewDockablePanel\n";
      }
      if(MyForm.capt!="") {
        vbs += MyForm.onam+".Caption = \""+MyForm.capt+"\"\n";
      }
      vbs += MyForm.onam+".DockedTo = "+MyForm.dock+"\n"; 
      if(MyForm.oclo!="") {
        vbs += "Script.RegisterEvent "+MyForm.onam+", \"OnClose\", \""+MyForm.oclo+"\"\n";
        addtosubs(MyForm.oclo);
      }
      if(MyForm.odoc!="") {
        vbs += "Script.RegisterEvent "+MyForm.onam+", \"OnDockChanged\", \""+MyForm.odoc+"\"\n";
        addtosubs(MyForm.odoc);
      }   
      break;
    case "opt":
      var sep = "\",\"";
      if(MyForm.slab=="") {
        MyForm.slab = MyForm.onam;
      }
      if(MyForm.init=="") {
        MyForm.init = "Init"+MyForm.onam;
      }
      if(MyForm.save=="") {
        MyForm.save = "Save"+MyForm.onam;
      }      
      vbs += "Call SDB.UI.AddOptionSheet(\""+MyForm.slab;
      if(MyForm.uses!="") {
        vbs += sep+obj.uses+sep;
      }
      else {
        vbs += "\",Script.ScriptPath,\"";
      }      
      vbs += MyForm.init+sep+MyForm.save+"\",";
      if(MyForm.pari>0) {
        vbs += "-"+MyForm.pari;
      }      
      else {
        vbs += "0";
      }
      vbs += ")\n"
      break;      
  }
  
  //create children
  if(MyForm.type!="opt") {
    vbs += commoncode(MyForm,MyForm.onam);
    for(var i=0;i<MyForm.kids.length;i++) {
      vbs += childcode(MyForm,MyForm.kids[i]);
    }
  }
   
  //add sheet procs
  if(MyForm.type=="opt") { 
    var v = 0;
    var t = s = f = "";
    vbs += "\nSub "+MyForm.init+"("+MyForm.onam+")";
    for(var i=0;i<MyForm.kids.length;i++) {
      var k = MyForm.kids[i];
      if(k.name=="") {
        k.name = k.onam;
      }
      t += childcode(MyForm,k);
      switch(k.type) {       
        case "drp":
          f = "ItemIndex";
          break;      
        case "edt":
          f = "Text";
          break;              
        case "chk":
          f = "Checked";
          break;             
        case "rad":
          f = "Checked";
          break;     
        case "spn":
          f = "Value";
          break;     
        case "bar":
          f = "Value";
          break;       
        default:
          f = "";
      }
      if(f!="") {
        v++;
        s += "  Dim val"+v+" : val"+v+" = "+MyForm.onam+".Common.ChildControl(\""+k.name+"\")."+f+"\n";
      }      
    }
    vbs += t.replace(/\n/g,"\n  ").replace(/\s+$/,"");
    vbs += "\nEnd Sub\n";   
    vbs += "\nSub "+MyForm.save+"("+MyForm.onam+")\n"+s+"End Sub\n";    
  }
  
  //add sub procedures
  for(var j=0;j<subs.length;j++) {
    vbs += "\nSub "+subs[j]+"(Control)\n  \nEnd Sub\n";
  }
  
  //end of form
  vbs += "\n'*******************************************************************'";
  vbs += "\n'* End of form                              Richard Lewis (c) 2007 *'";
  vbs += "\n'*******************************************************************'";    
  vbs += "</textarea></p>";
  
  //add resizer
  vbs += "<div id='resizer' style='position:absolute;top:0px;left:0px;height:12px;width:12px;border:1px solid black' ";
  vbs += "onmousedown='return startresizer(event)' onmouseup='return stopresizer(event)'>";
  vbs += "<img src='imgs/resize.png' alt='%'></div>";
  
  //create options
  var opt = "<br><form action='https://www.paypal.com/cgi-bin/webscr' method='post' target='_blank'>";
  opt += "<input type='hidden' name='cmd' value='_s-xclick'><center>";
  opt += "<input type='image' src='https://www.paypal.com/en_US/i/btn/x-click-but04.gif' border='0' name='submit' alt='Please donate!' title='Donate to MMVBS'></center>";
  opt += "<input type='hidden' name='encrypted' value='-----BEGIN PKCS7-----MIIHHgYJKoZIhvcNAQcEoIIHDzCCB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AQkFMQ8XDTA1MTAyMzExMTQxNFowIwYJKoZIhvcNAQkEMRYEFEEHCiTMeyclqntINP/vNQHGM+2/MA0GCSqGSIb3DQEBAQUABIGAerEbjO73Qseiv5ub43NiYuU7KCqAsubpkX2khb4Rnsll6c223ONRt4QyzHnGKVtBiZld6Iw4ThAva9Q7w86XtmXrIltIOuufYPWgHB3PAI68OYQ78/Vk4qWDod52UZjkECAl2AlcA638ScJm97EArjipV9V73Bq9W+D1Adu3Uqk=-----END PKCS7-----'>";
  opt += "</form><br><p align='center'>";  
  opt += "<a href='javascript://Copy to clipboard' onclick='codetoclip();' title='Copy to clipboard'>";
  opt += "<img src='imgs/clip.png' alt='Copy to clipboard' border=0></a></br></br>";
  opt += "<a href='javascript://Download as file' onclick='codetofile();' title='Download as file'>";
  opt += "<img src='imgs/file.png' alt='Download as file' border=0></a></br></br>";
  opt += "<a href='javascript://Email as attachment' onclick='codetomail();' title='Email as attachment'>";
  opt += "<img src='imgs/mail.png' alt='Email as attachment' border=0></a></p>";
  
  //display code
  document.getElementById('form').innerHTML = vbs;
  document.getElementById('prop').innerHTML = opt;  
  document.getElementById('tool').innerHTML = "";  
  snapsize();
  
  //update tabs
  view = 4;
  document.getElementById('tabs').innerHTML = addtabs();
  return true;
}

function childcode(par,obj) {
  var kid = "\n";
  var caption = ""
  switch(obj.type) {
    case "act":
      kid += "Dim "+obj.onam+" : Set "+obj.onam+" = SDB.UI.NewActiveX";
      kid += "("+par.onam+",\""+obj.comp+"\")\n";
      break;
    case "but":
      kid += "Dim "+obj.onam+" : Set "+obj.onam+" = SDB.UI.NewButton";
      kid += "("+par.onam+")\n";
      if(obj.canc) {
        kid += obj.onam+".Cancel = True\n";
      }      
      if(obj.capt!="") {
        kid += obj.onam+".Caption = \""+obj.capt+"\"\n";
      }
      if(obj.defa) {
        kid += obj.onam+".Default = True\n";
      }       
      if(obj.mres>0) {
        kid += obj.onam+".ModalResult = "+obj.mres+"\n";
      }
      if(obj.func!="") {
        if(obj.uses!="") {
          kid += obj.onam+".UseScript = \""+obj.uses+"\"\n";
        }
        else {
          kid += obj.onam+".UseScript = Script.ScriptPath\n";
          addtosubs(obj.func);
        }
        kid += obj.onam+".OnClickFunc = \""+obj.func+"\"\n";
      }       
      if(obj.oclk!="") {
        kid += "Script.RegisterEvent "+obj.onam+", \"OnClick\", \""+obj.oclk+"\"\n";
        addtosubs(obj.oclk);
      }      
      break;      
    case "drp":
      kid += "Dim "+obj.onam+" : Set "+obj.onam+" = SDB.UI.NewDropDown";
      kid += "("+par.onam+")\n";
      if(obj.itms!="") {
        var str = "\""+obj.itms+"\"";
        str = str.replace(/,/g,"\",\"");
        eval("var arr = new Array("+str+");");
        for(var i=0;i<arr.length;i++) {
          kid += obj.onam+".AddItem(\""+arr[i]+"\")\n";
        }      
      }
      if(obj.itmi>-1) {
        kid += obj.onam+".ItemIndex = "+obj.itmi+"\n";
      }      
      if(obj.text!="") {
        kid += obj.onam+".Text = \""+obj.text+"\"\n";
      }    
      if(obj.styl>0) {
        kid += obj.onam+".Style = "+obj.styl+"\n";
      }       
      if(obj.func!="") {
        if(obj.uses!="") {
          kid += obj.onam+".UseScript = \""+obj.uses+"\"\n";
        }
        else {
          kid += obj.onam+".UseScript = Script.ScriptPath\n";
          addtosubs(obj.func);
        }
        kid += obj.onam+".OnSelectFunc = \""+obj.func+"\"\n";
      }      
      if(obj.osel!="") {
        kid += "Script.RegisterEvent "+obj.onam+", \"OnSelect\", \""+obj.osel+"\"\n";
        addtosubs(obj.osel);
      }            
      break;      
    case "edt":
      kid += "Dim "+obj.onam+" : Set "+obj.onam+" = SDB.UI.NewEdit";
      kid += "("+par.onam+")\n";
      if(obj.text!="") {
        kid += obj.onam+".Text = \""+obj.text+"\"\n";
      }    
      break;      
    case "chk":
      kid += "Dim "+obj.onam+" : Set "+obj.onam+" = SDB.UI.NewCheckBox";
      kid += "("+par.onam+")\n";      
      if(obj.capt!="") {
        caption = obj.capt.replace(/\\n/g,"\"+Chr(13)+\"");
        kid += obj.onam+".Caption = \""+caption+"\"\n";
      }    
      if(obj.chkd) {
        kid += obj.onam+".Checked = True\n";
      }       
      break;            
    case "lbl":
      kid += "Dim "+obj.onam+" : Set "+obj.onam+" = SDB.UI.NewLabel";
      kid += "("+par.onam+")\n";
      if(obj.algn>0) {
        kid += obj.onam+".Alignment = "+obj.algn+"\n";
      }      
      if(!obj.auto) {
        kid += obj.onam+".Autosize = False\n";
      }       
      if(obj.mult) {
        kid += obj.onam+".Multiline = True\n";
      }       
      break; 
    case "pan":
      kid += "Dim "+obj.onam+" : Set "+obj.onam+" = SDB.UI.NewPanel";
      kid += "("+par.onam+")\n";      
      break;
    case "rad":
      kid += "Dim "+obj.onam+" : Set "+obj.onam+" = SDB.UI.NewRadioButton";
      kid += "("+par.onam+")\n";      
      if(obj.capt!="") {
        caption = obj.capt.replace(/\\n/g,"\"+Chr(13)+\"");
        kid += obj.onam+".Caption = \""+caption+"\"\n";
      }    
      if(obj.chkd) {
        kid += obj.onam+".Checked = True\n";
      }       
      break;    
    case "spn":
      kid += "Dim "+obj.onam+" : Set "+obj.onam+" = SDB.UI.NewSpinEdit";
      kid += "("+par.onam+")\n";      
      if(obj.maxv!=0) {
        kid += obj.onam+".MaxValue = "+obj.maxv+"\n";
      }  
      if(obj.minv!=0) {
        kid += obj.onam+".MinValue = "+obj.minv+"\n";
      }  
      kid += obj.onam+".Value = "+obj.valu+"\n";     
      break;  
    case "bar":
      kid += "Dim "+obj.onam+" : Set "+obj.onam+" = SDB.UI.NewTrackBar";
      kid += "("+par.onam+")\n"; 
      if(!obj.hori) {
        kid += obj.onam+".Horizontal = False\n";
      }       
      if(obj.maxv!=0) {
        kid += obj.onam+".MaxValue = "+obj.maxv+"\n";
      }  
      if(obj.minv!=0) {
        kid += obj.onam+".MinValue = "+obj.minv+"\n";
      }  
      kid += obj.onam+".Value = "+obj.valu+"\n";     
      break;       
    case "tra":
      kid += "Dim "+obj.onam+" : Set "+obj.onam+" = SDB.UI.NewTranspPanel";
      kid += "("+par.onam+")\n";      
      break;
  }
  kid += commoncode(obj,obj.onam);

  //fix label caption
  if(obj.type=="lbl" && obj.capt!="") {
    caption = obj.capt.replace(/\\n/g,"\"+Chr(13)+\"");
    kid += obj.onam+".Caption = \""+caption+"\"\n";
  }   
  
  //recurse
  if(obj.kids!=null) {
    for(var i=0;i<obj.kids.length;i++) {
      kid += childcode(obj,obj.kids[i]);
    }
  }
  return kid;
}

function commoncode(obj,nam) {
  //set common options
  nam = nam+".Common.";
  var com = nam+"SetRect "+obj.left+","+obj.top+","+obj.widt+","+obj.heig+"\n";
  if(obj.alig>0) {
    com += nam+"Align = "+obj.alig+"\n";
  }  
  if(obj.anch>0) {
    com += nam+"Anchors = "+obj.anch+"\n";
  } 
  if(obj.name!="" && obj.type!="doc") {
    com += nam+"ControlName = \""+obj.name+"\"\n";
  }  
  if(!obj.enab) {
    com += nam+"Enabled = False\n";
  }  
  if(obj.hint!="") {
    com += nam+"Hint = \""+obj.hint+"\"\n";
  }   
  if(obj.maxh>0) {
    com += nam+"MaxHeight = "+obj.maxh+"\n";
  }   
  if(obj.maxw>0) {
    com += nam+"MaxWidth = "+obj.maxw+"\n";
  } 
  if(obj.minh>0) {
    com += nam+"MinHeight = "+obj.minh+"\n";
  } 
  if(obj.minw>0) {
    com += nam+"MinWidth = "+obj.minw+"\n";
  }   
  if(!obj.visi) {
    com += nam+"Visible = False\n";
  }  
  if(obj.ocli!="") {
    com += "Script.RegisterEvent "+nam+", \"OnClick\", \""+obj.ocli+"\"\n";
    addtosubs(obj.ocli);
  }      
  if(obj.ores!="") {
    com += "Script.RegisterEvent "+nam+", \"OnResize\", \""+obj.ores+"\"\n";
    addtosubs(obj.ores);
  }            
  return com;
}

function addtosubs(itm) {
  //check duplicate
  var dup = false;
  for(var i=0;i<subs.length;i++) {
    if(subs[i]==itm) {
      dup = true;
      i = subs.length;
    }
  }
  //add item
  if(!dup) {
    subs.push(itm);
  }
}

function codetoclip() {
  //copy code to clipboard
  var code = document.getElementById('code');
  if(document.all) {
    code.createTextRange().execCommand("Copy");
    alert('The code has been copied!');
  } 
  else {
    if (window.netscape) //mozilla
    {  
      try {
        //user_pref("signed.applets.codebase_principal_support", true);
	netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
      } 
      catch (e) {
	alert('Sorry, the code could not be copied.');
	return false;
      }      
      var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
      if (!clip) return;
      var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
      if (!trans) return;
      trans.addDataFlavor('text/unicode');
      var str = new Object();
      var len = new Object();
      var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
      var copytext = code.value;
      str.data = copytext;
      trans.setTransferData("text/unicode",str,copytext.length*2);
      var clipid = Components.interfaces.nsIClipboard;
      if (!clipid) return false;
      clip.setData(trans,null,clipid.kGlobalClipboard);
      alert('The code has been copied!');
    }
    else {
      alert('Sorry, the code could not be copied.');
      return false;
    }
  }
  return true;
}

function codetofile() {
  //copy code to file and download
  var code = document.getElementById('code');
  ajax_send("file",code.value);
  return true;
}

function codetomail() {
  //copy code to file and email
  var code = document.getElementById('code');
  var email = prompt("Email address:","");
  if(email != null && email.indexOf("@")>0) {
    ajax_send(email,code.value);
  }
  return true;
}

var a = null;
function ajax_init() {
  if (window.XMLHttpRequest) {
    a = new XMLHttpRequest();
  }
  else {
    try {
      a = new ActiveXObject("Msxml2.XMLHTTP");
    } 
    catch (e1) {
      try {
        a = new ActiveXObject("Microsoft.XMLHTTP");
      } 
      catch (e2) {
        a = null;
      }
    }
  }
  return a;
} 
 
function ajax_send(del,mes) {
  if(a==null) {
    a = ajax_init();
    if(a) {
      a.open("POST","copy.php",true);
      a.onreadystatechange = function () {
        if (a.readyState == 4) {
          if (a.status == 200) {
            if(a.responseText.indexOf("<OK>")==0) {
              if(a.responseText.indexOf("@")==4) {
                alert(a.responseText.substr(5));
                a = null;
              }
              else {
                document.location = 'get.php?file='+a.responseText.substr(4);
                a = null;
              }  
            }
            else {
              alert(a.responseText);
              a = null;
              return false;
            }
          }
          else {
            alert('Sorry, the file could not be created.');
            a = null;
            return false;
          }
        }
        return true;
      }
      a.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
      a.send("deliver="+del+"&message="+mes); 
    }
    else { 
      alert('Sorry, the file could not be created.');
      a = null;
      return false;
    }
  }
  return true;
}

function selectobj(nam) {
  findobj(MyForm,nam);
  return showform();
}

function findobj(obj,nam) {
  //check object found
  if(obj.onam==nam) {
    MyProp = obj;
    return true;
  }
  //recurse through kids
  var arr = obj.kids;
  if(arr!=null) {
    for(var i=0;i<arr.length;i++) {
      if(findobj(arr[i],nam)) {
        return true;
      }
    }
  } 
  return false;
}

function findpos(div) {
  var curleft = curtop = 0;
  if (div.offsetParent) {
    curleft = div.offsetLeft;
    curtop = div.offsetTop;
    while (div = div.offsetParent) {
      curleft += div.offsetLeft;
      curtop += div.offsetTop;
    }
  }
  return [curleft,curtop];
}

function findpoint(obj) {
  var pl = pt = 0;
  if(obj!=MyForm) {  
    if(obj.prnt!=null) {
      var coo = findpoint(obj.prnt);
      pl = coo[0];
      pt = coo[1];
    }    
    pl += obj.left+1;
    pt += obj.top;
  }
  return [pl,pt];
}

function setpointer() {
  if (!MyProp.visi) {
    return "";
  }
  var coo = findpoint(MyProp);
  var pnt = document.getElementById("pointer");
  pnt.style.display = "inline";
  pnt.style.left = coo[0];
  if(MyProp==MyForm) {
    pnt.style.top = coo[1];
  }
  else {
    pnt.style.top = coo[1]+thick;
  }
  return true;
}